#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import time
import json
import re

def zan():
    A = requests.Session()
    try:
        html = A.get(r'http://campus.finance365.com/Rematch/UserCenter/38').content
        hid = re.findall('val = "([^"]+)"', html)[0]
    except requests.exceptions.ConnectionError:
        print '联网失败，请检查网络 或者 查看是否该网站已死～～'
        exit()
    except :
        print "未知原因"
        exit()
    
    for daily_no in ['317', '43', '110', '232', '169']:
        # payload = {'daily_no':daily_no, 'hid':hid}
        payload = {'daily_no':daily_no, 'aid':'8wwc'}
        result = A.post(r'http://campus.finance365.com/Rematch/PraiseDaily', params=payload)
        jsondata = json.loads(result.text)

        print jsondata.get('Msg')
        time.sleep(randint(20, 30))

if __name__ == '__main__':
    from random import randint
    max_num = raw_input("Max Votes For XiaoYingzi: ")
    try:
        max_num = int(max_num)
    except ValueError:
        raw_input("Input Error, Exit, And Try Again")
        exit()

    if max_num >= 1000:
        print "哎呀呀, 小颖子, 你对人家不要这么暴力嘛^_^"
        raw_input("请重新来过")
        exit()

    for i in range(max_num):
        zan()
        print "小颖子,请让我休息两秒^_^"
        print ""
        stop_time = randint(600, 620)
        print "Wait Seconds: " + str(stop_time)
        time.sleep(stop_time)
